package com.test;


import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Xml {

	public static void main(String[] args) {
        //创建DOM4J解析器对象
     SAXReader saxReader = new SAXReader();
     try {
    	 String path = "D:\\jackWorkSpace\\double4county\\src\\main\\webapp\\WEB-INF\\view\\mp\\report\\baseReport\\list.jsp";
         //读取xml文件，并生成document对象 现可通过document来操作文档
         Document document = saxReader.read(path);
         //获取到文档的根节点
         Element rootElement = document.getRootElement();
         System.out.println("根节点的名字是:" + rootElement.getName());
         //获取子节点列表
         Iterator it = rootElement.elementIterator();
         while (it.hasNext()) {
             Element fistChild = (Element) it.next();
             //System.out.println(fistChild.getName());
             //获取节点的属性值
             System.out.println(fistChild.attribute("name").getValue());
             //获取子节点的下一级节点
             Iterator iterator = fistChild.elementIterator();
             while (iterator.hasNext()) {
                 Element element = (Element) iterator.next();
                 System.out.println("\t" + element.attributeValue("name"));
             }
         }
     } catch (DocumentException e) {
         e.printStackTrace();
     }
 }
}
